﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Utility;
using Utility.Model;

namespace MsgCenter.Web.Handlers
{
    /// <summary>
    /// Handler_Write 的摘要说明
    /// </summary>
    public class Handler_Write : BaseUI.BaseHandler
    {
        public void Write_MySend()
        {
            string strUserID = ParamsOfRequest.Request("UserID");
            string strSendContent = ParamsOfRequest.Request("sendContent");
            string strSendType = ParamsOfRequest.Request("sendType");
            string strSendDate = ParamsOfRequest.Request("sendDate");
            string strSendTime = ParamsOfRequest.Request("sendTime");
            string strIsAutoSend = ParamsOfRequest.Request("IsAutoSend");
            try
            {
                List<Sys_User> listUser = BLL.BLLServiceHelper.GetBaseDataService().GetList<Sys_User>(Sys_User._.UserID.SelectIn(strUserID.Split(',')));
                List<Sys_Dic> listDic = BLL.BLLServiceHelper.GetBaseDataService().GetList<Sys_Dic>(Sys_Dic._.DicID.SelectIn(strSendType.Split(',')));

                TB_SMS_Message message = null;
                List<TB_SMS_Message> listMessage = new List<TB_SMS_Message>();
                foreach (Sys_Dic dicModel in listDic)
                {
                    foreach (Sys_User userModel in listUser)
                    {
                        message = new TB_SMS_Message();
                        message.BussinessID = "";
                        if (strIsAutoSend.ToSafeInt() == 1)
                        {
                            message.IsInstant = 1;
                            message.SendDate = DateTime.Now;
                        }
                        else
                        {
                            message.IsInstant = 0;
                            message.SendDate = (strSendDate + " " + strSendTime).ToSafeDateTime();
                        }
                        message.IsRead = 0;
                        message.Messge = strSendContent;
                        message.Mobile1 = userModel.Mobile;
                        message.Mobile2 = userModel.Mobile;
                        message.QQ = userModel.QQ;
                        message.ReceiveLoginName = userModel.UserName;
                        message.ReceiveUserName = userModel.Name;
                        message.RtxLoginName = userModel.RtxLoginName;
                        message.SendIP = base.IP;
                        message.SendLoginName = base.Account;
                        message.SendType = dicModel.DicName;
                        message.SendUserName = base.UserInfo.Name;
                        message.SiteLoginName = userModel.UserName;
                        message.SystemCode = "MessageCenter";
                        message.WebChat = userModel.WebChat;
                        listMessage.Add(message);
                    }
                }
                BLL.BLLServiceHelper.GetWriteService().Save(listMessage);
                base.GetSuccessJson();
            }
            catch (Exception ex)
            {
                base.GetFailureJson(ex.Message);
            }
        }



    }
}